package com.ldl.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.ldl.dao.CountDao;
import com.ldl.entity.Count;
import com.ldl.util.DBHelper;

/**
 * @author Administrator
 * Author : L.D.L
 * E-mail : 1419485293@qq.com
 * Date : 2020年8月7日下午4:58:15
 */
public class CountDaoImpl implements CountDao{

	@Override
	public Count select() throws SQLException {
		String sql = "select * from count";
		try(
				Connection conn = DBHelper.getConn();
				PreparedStatement ps = conn.prepareStatement(sql);
				ResultSet res = ps.executeQuery();
			){
			Count count = new Count();
			while(res.next()){
				count.setCount(res.getInt("count"));
			}
			return count;
		}
		
	}

	@Override
	public int update(int count) throws SQLException {
		String sql = "update count set count ="+count;
		try(
				Connection conn = DBHelper.getConn();
				PreparedStatement ps = conn.prepareStatement(sql);
			) {
			return ps.executeUpdate();
		} 
	}

	@Override
	public int insert(Count count) throws SQLException {
		String sql = "insert into count value("+count.getCount()+")";
		try (
				Connection conn = DBHelper.getConn();
				PreparedStatement ps = conn.prepareStatement(sql);
			){
			return ps.executeUpdate();
		} 
	}

}
